<template>
  <el-button @click="handleClick"
             :class="arrowClass"
             :type="type">{{title}}</el-button>
</template>

<script>
import axios from 'axios'

export default {
  name: "OrderUpdateLink",
  props: {
    orderId: Number,
    type: String,
    title: String,
    arrow: Boolean
  },
  data () {
    return {

    }
  },
  computed: {
    validateUrl () {
      return "/order/orderGoods/sign/receipt/record/check/" + this.orderId;
    },
    arrowClass () {
      return this.arrow ? 'arrow' : ''
    }
  },
  methods: {
    confirm () {
      this.$confirm(
        "货物信息已做了异常物品数量登记，确定修改后会清除!",
        "温馨提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.go()
      }).catch(() => {
        this.$message({
          type: "info",
          message: "已取消"
        });
      });
    },
    go () {
      this.$router.push({
        name: 'createOrder',
        query: {
          orderId: this.orderId
        }
      })
    },
    async processLink () {
      const response = await axios.get(this.validateUrl);
      if (0 === response?.code) {
        if (response.data) {
          this.confirm();
        } else {
          this.go();
        }
        // this.$message({
        //   type: "success",
        //   message: "操作成功"
        // });
      }
    },
    handleClick () {
      this.$emit("click");
      this.processLink();
    }
  }
}
</script>


<style scoped lang="scss">
.arrow {
  color: var(--prev-color-text-regular);
  font-size: 13px;
  padding: 0;
}

.btn-wrap {
  // text-align: center;
  .son-span {
    padding: 0 6px;
  }
}

.more {
  // font-size: 12px;
  padding: 0 6px;
}

.average-link {
  display: flex;
  justify-content: center;
  align-items: center;
}

.first-span {
  border-left: 1px solid var(--prev-border-color-grey);
  border-right: 1px solid var(--prev-border-color-grey);
  padding: 0 6px;
  border-radius: 0px;
}

.iconClass {
  height: 13px;
  padding: 0 7px;
}

.el-dropdown {
  cursor: pointer;
}

.border-right {
  border-right: 0px;
}
</style>